package com.wgzx.modbus.entity.request;

import com.wgzx.modbus.entity.ModbusReq;

import static com.wgzx.modbus.constant.FunctionCode.READ_INPUT_REGISTERS;
import static com.wgzx.modbus.util.ModbusUtil.validateRange;

/**
 * 读输入寄存器 <br/>
 * 功能码：0x04 <br/>
 * 起始地址：2个字节0x0000至0xFFFF <br/>
 * 寄存器数量：2个字节0x0001至0x007D <br/>
 *
 * @author gexin
 */
public class ReadInputRegistersRequest extends ModbusReq {

    public ReadInputRegistersRequest(int startingAddress, int quantityOfInputRegisters) {
        super(READ_INPUT_REGISTERS, startingAddress, quantityOfInputRegisters);
        validateRange(startingAddress, "startingAddress", 0x00, 0xFFFF);
        validateRange(quantityOfInputRegisters, "quantityOfInputRegisters", 0x01, 0x007D);
    }

    @Override
    public String toString() {
        return "ReadInputRegistersRequest{" + "startingAddress=" + address + ", quantityOfInputRegisters=" + value + '}';
    }
}
